{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/msgGrowl/css/msgGrowl.css" rel="stylesheet">
    <link href="{{ path }}js/plugins/msgAlert/css/msgAlert.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/lightbox/themes/evolution-dark/jquery.lightbox.css" rel="stylesheet">  
    <link href="{{ path }}js/plugins/timepicker/jquery.ui.timepicker.css" rel="stylesheet"> 
	<link href="{{ path }}js/plugins/colorpicker/css/colorpicker.css" rel="stylesheet">
    <link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
	<script src="{{ path }}js/plugins/msgGrowl/js/msgGrowl.js"></script>
	<script src="{{ path }}js/plugins/msgAlert/js/msgAlert.js"></script>
    <script src="{{ path }}js/plugins/timepicker/jquery.ui.timepicker.min.js"></script>
    <script src="{{ path }}js/plugins/colorpicker/js/bootstrap-colorpicker.js"></script>
    <script src="{{ path }}js/plugins/lightbox/jquery.lightbox.js"></script>
    <script src="{{ path }}js/demos/demo.ui-elements.js"></script>

	
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    {{ path2 }}    
{% endblock %}

{% block jquery %}
    $( 'form' ).submit(function() {
    	if($('#contrasena-actual').attr('value') != ""){
            if($('#contrasena-nueva').attr('value') == $('#re-contrasena').attr('value')){
                return true;
            }
            else{
                alert("Las contraseñas no coinciden.");
                return false;
            }
		}
        else{
        }
    });

    $( '.guardar-facultad' ).click(function() {
    	if($('#facultad-nombre').attr('value') != ""){
            sigla = $('#facultad-sigla').attr('value');
            nombre = $('#facultad-nombre').attr('value');
            semestres = $('#facultad-semestres').attr('value');
            $.ajax({
                url: "/configuracion/facultades/",
                type: "POST",
                data : {sigla:sigla, 
                        nombre:nombre, 
                        semestres:semestres, 
                        csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                         },
                dataType: "html",
                success: function(datos) {
                    $('#facultad-opciones-der').html(datos);
                }
            });
        }
        else{
            alert("Debe digitar el nombre de facultad.");
        }
    });
    
        
    $( '#cancelar' ).click(function() {
        location.href = "/busqueda";
    });

	$( '#chk-fin-mes' ).click(function() {
    	if($("#chk-fin-mes").is(":checked")){
        	$("#periodo-cuotas").prop('disabled', true);
        }
        else{
        	$("#periodo-cuotas").prop('disabled', false);
        }
    });

	$("#btn-notificar").click(function() {
        if(confirm('Se enviarán correos electrónicos a los deudores morosos. ¿Desea continuar?')){
			moroso = $('#morosos-email').attr('value');
			$.ajax({
					url: "/configuracion/notificacion/mora/",
					type: "POST",
					data : { 
							moroso:moroso, 
							csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
							},
					dataType: "html",
					success: function(datos) {
						alert(datos);
						location.reload(true);
					}
				});
		}
    });
{% endblock %}
	
{% block ruta %}
		
{% endblock %}

{% block contenido %}
    <div class="span6">
    	<div id="horizontal" class="widget widget-form">
            <div class="widget-header">	      				
                <h3>
                    <i class="icon-pencil"></i>
                    Datos Institucionales
                </h3>
            </div> <!-- /widget-header -->
            
            <div class="widget-content">
                
				<form id="form-institucion" class="form-horizontal" action="/configuracion/guardar/" method="post" enctype="multipart/form-data">
			    {% csrf_token %}
    		    <fieldset>
                    <div class="control-group">
                        <label class="control-label" for="input01">Institución</label>
                        <div class="controls">
                        	<input type="text" class="input-large" name="institucion" id="institucion" required="required" value="{{ configuracion.institucion }}"/>
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Logo</label>
                        <div class="controls">
                            <input type="file" id="foto" name="foto" class="input-file" accept="image/gif,image/jpeg">
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Recordatorio SMS</label>
                        <div class="controls">
                        	<input type="Number" class="input-small" name="dias-sms" id="dias-sms" min="0" required="required" value="{{ configuracion.recordatorio_sms }}"/> dias antes de la fecha de vencimiento.
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Recordatorio EMAIL</label>
                        <div class="controls">
                        	<input type="Number" class="input-small" name="dias-email" id="dias-email" min="0" value="{{ configuracion.recordatorio_email }}"/> dias antes de la fecha de vencimiento.
                        </div>
					</div>

                    <div class="control-group">
                        <label class="control-label" for="input01">SMS Morosos cada:</label>
                        <div class="controls">
                        	<input type="Number" class="input-small" name="morosos-sms" id="morosos-sms" min="0" required="required" value="{{ configuracion.sms_moroso }}"/> dias.
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">EMAIL Morosos cada:</label>
                        <div class="controls">
                        	<input type="Number" class="input-small" name="morosos-email" id="morosos-email" min="0" required="required" value="{{ configuracion.email_moroso }}"/> dias.
                        </div>
					</div>
					
					<div class="control-group">
                        <label class="control-label" for="input01">Tasa Interés M.V.</label>
                        <div class="controls">
                        	<input type="text" class="input-small" name="tasa-interes" id="tasa-interes" value="{{ configuracion.tasa_interes }}"/>
                        </div>
					</div>
                    
					<div class="control-group">
                        <label class="control-label" for="input01">Notificar a Morosos vía e-mail:</label>
                        <div class="controls">
                        	<button id="btn-notificar" type="button" class="btn btn-medium">Notificar</button>
							{% if f_notificacion != "" %}
								<div id="notificacion">La última notificación se realizó: {{ f_notificacion }}.</div>
							{% endif %}
                        </div>
					</div>
					
                    <div class="control-group">
                        <label class="control-label" for="input01">Email</label>
                        <div class="controls">
                        	<input type="email" class="input-large" name="email" id="email" required="required" value="{{ configuracion.usuario.email }}"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Contraseña actual:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="contrasena-actual" id="contrasena-actual"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Nueva contraseña:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="contrasena-nueva" id="contrasena-nueva"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Confirmar contraseña:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="re-contrasena" id="re-contrasena"/>
                        </div>
					</div>
                    
                    {% if texto %}
                        <div class="alert alert-block">
                          <a class="close" data-dismiss="alert" href="#">&times;</a>
                          <!--<h4 class="alert-heading">Error actualizando la contraseña:</h4>-->
                        </div>
					{% endif %}
            		<div class="form-actions">
                        <button type="submit" class="btn btn-primary btn-large">Guardar</button>
                  	</div>
	            	</fieldset>
          		</form>	
                </div> <!-- /.widget-content -->	
				</div> <!-- /.horizontal -->
			</div> <!-- /.span6 -->
            
            
            <div class="span6">
                <div id="horizontal" class="widget widget-form">
                    <div class="widget-header">	      				
                        <h3>
                            <i class="icon-pencil"></i>
                            Periodos
                        </h3>
                    </div> <!-- /widget-header -->
                    
                    <div class="widget-content">
                    	<form action="/configuracion/periodos/borrar/" method="post">
                        {% csrf_token %}
                        <table class="table table-bordered table-striped table-highlight">
                            <thead>
                                <tr>
                                	<th width="5%"></th>
                                    <th width="25%">Periodo</th>
                                    <th width="20%">Inicio</th>
                                    <th width="20%">Fin</th>
                                    <th width="20%">Corte</th>
                                    <th width="10%">Meses</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for periodo in Periodos %}
                                <tr>
                                    <td><input type="checkbox" id="chk_{{periodo.id}}" name="chk_{{periodo.id}}" value="false"/></td>
                                    <td>{{ periodo.nombre }}</td>
                                    <td>{{ periodo.fecha_inicio|date:'d-m-Y' }}</td>
                                    <td>{{ periodo.fecha_fin|date:'d-m-Y' }}</td>
                                    <td>{{ periodo.corte_fin_mes|date:'d-m-Y' }}</td>
                                    <td>{{ periodo.meses }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
						<table width="100%" class="form-actions">
                        	<tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-primary btn-medium">Borrar Periodos</button></td>
	                        <td width="50%" style="text-align:center"><a href="#myModalP" data-toggle="modal" class="btn btn-primary btn-medium">Nuevo Periodo</a></td></tr>
    	                </table>        
         
                        </form>
                	</div> <!-- /.widget-content -->	
					

				</div> <!-- /.horizontal -->
			</div> <!-- /.span6 -->
            
            <div class="span6">
            		<div id="horizontal" class="widget widget-form">
                        <div class="widget-header">	      				
                            <h3>
                                <i class="icon-pencil"></i>
                                Facultades
                            </h3>
                        </div> <!-- /widget-header -->
                        
                        <div class="widget-content">
                        	<form action="/configuracion/facultades/borrar/" method="post">
							{% csrf_token %}
                		    	<table class="table table-bordered table-striped table-highlight">
                                	<thead>
                                        <tr>
                                        	<th width="5%"></th>
                                            <th width="20%">Sigla</th>
                                            <th width="60%">Nombre</th>
                                            <th width="15%">Semestres</th>
                                        </tr>
									</thead>
                                    <tbody>
                                        {% for facultad in Facultades %}
                                        <tr>
                                        	<td><input type="checkbox" id="chk_{{facultad.id}}" name="chk_{{facultad.id}}" value="false"/></td>
                                            <td>{{ facultad.sigla }}</td>
                                            <td>{{ facultad.nombre }}</td>
                                            <td>{{ facultad.semestres }}</td>
                                        </tr>
                                        {% endfor %}
									</tbody>
                                </table>
                                
                                <table width="100%" class="form-actions">
                                    <tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-primary btn-medium">Borrar Facultades</button></td>
                                    <td width="50%" style="text-align:center"><a href="#myModalF" data-toggle="modal" class="btn btn-primary btn-medium">Nueva Facultad</a></td></tr>
                                </table>
							</form>
                        </div> <!-- /. widget-content -->
					</div>	<!-- horizontal -->
			</div> <!-- /. span6 -->
			
			<div class="span6">
            		<div id="horizontal" class="widget widget-form">
                        <div class="widget-header">	      				
                            <h3>
                                <i class="icon-pencil"></i>
                                Conceptos
                            </h3>
                        </div> <!-- /widget-header -->
                        
                        <div class="widget-content">
                        	<form action="/configuracion/conceptos/borrar/" method="post">
							{% csrf_token %}
                		    	<table class="table table-bordered table-striped table-highlight">
                                	<thead>
                                        <tr>
                                        	<th width="5%"></th>
                                            <th width="25%">Codigo</th>
                                            <th width="70%">Descripción</th>
                                        </tr>
									</thead>
                                    <tbody>
                                        {% for concepto in Conceptos %}
                                        <tr>
                                        	<td><input type="checkbox" id="chk_{{concepto.id}}" name="chk_{{concepto.id}}" value="false"/></td>
                                            <td>{{ concepto.codigo }}</td>
                                            <td>{{ concepto.nombre }}</td>
                                        </tr>
                                        {% endfor %}
									</tbody>
                                </table>
                                
                                <table width="100%" class="form-actions">
                                    <tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-primary btn-medium">Borrar Conceptos</button></td>
                                    <td width="50%" style="text-align:center"><a href="#myModalC" data-toggle="modal" class="btn btn-primary btn-medium">Nuevo Concepto</a></td></tr>
                                </table>
							</form>
                        </div> <!-- /. widget-content -->
					</div>	<!-- horizontal -->
			</div> <!-- /. span6 -->
		</div>
	</div>


    <div class="modal fade hide" id="myModalP">
		<form id="form-periodos" class="form-horizontal" action="/configuracion/periodos/" method="post">
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nuevo Periodo</h3>
              </div>
              <div class="modal-body">
                    {% csrf_token %}
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label" for="input01">Periodo:</label>
                            <div class="controls">
                                <input type="text" class="input-large" name="periodo-nombre" id="periodo-nombre" required="required" value=""/>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="input01">Inicio:</label>
                            <div class="controls">
                                <input class="input-medium" name="periodo-inicio" id="datepicker-basic" type="text" required="required" value="">
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="input01">Fin:</label>
                            <div class="controls">
                                <input class="input-medium" name="periodo-fin" id="datepicker-basic2" type="text" required="required" value="">
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="input01">Corte fin de mes:</label>
                            <div class="controls">
                                <input type="checkbox" id="chk-fin-mes" name="chk-fin-mes"/>
                              </label>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="input01">Cuotas:</label>
                            <div class="controls">
                                <input type="Number" class="input-small" name="periodo-cuotas" id="periodo-cuotas" min="0" value="0"/>
                            </div>
                        </div>
	            	</fieldset>
              </div>
              <div class="modal-footer">
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
                <a href="#" class="btn btn-primary btn-medium" data-dismiss="modal">Cerrar</a>
              </div>
          </form>
    </div>
    
    
    
	<div class="modal fade hide" id="myModalF">
		<form id="form-facultades" class="form-horizontal" action="/configuracion/facultades/" method="post">
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nueva Facultad</h3>
              </div>
              <div class="modal-body">
                    {% csrf_token %}
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label" for="input01">Sigla:</label>
                            <div class="controls">
                                <input type="text" class="input-large" name="facultad-sigla" id="facultad-sigla" required="required" value=""/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="input01">Nombre:</label>
                            <div class="controls">
                                <input type="text" class="input-large" name="facultad-nombre" id="facultad-nombre" required="required" value=""/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="input01">Semestres:</label>
                            <div class="controls">
                            	<input type="Number" class="input-small" name="facultad-semestres" id="facultad-semestres" required="required"  min="0" value="0"/>
                            </div>
                        </div>
                    </fieldset>
              </div>
              <div class="modal-footer">
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
                <a href="#" class="btn btn-primary btn-medium" data-dismiss="modal">Cerrar</a>
              </div>
		</form>
	</div>
	
	
	<div class="modal fade hide" id="myModalC">
		<form id="form-conceptos" class="form-horizontal" action="/configuracion/conceptos/" method="post">
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nuevo Concepto</h3>
              </div>
              <div class="modal-body">
                    {% csrf_token %}
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label" for="input01">Codigo:</label>
                            <div class="controls">
                                <input type="text" class="input-large" name="concepto-codigo" id="concepto-codigo" required="required" value=""/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="input01">Nombre:</label>
                            <div class="controls">
                                <input type="text" class="input-large" name="concepto-nombre" id="concepto-nombre" required="required" value=""/>
                            </div>
                        </div>
                    </fieldset>
              </div>
              <div class="modal-footer">
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
                <a href="#" class="btn btn-primary btn-medium" data-dismiss="modal">Cerrar</a>
              </div>
		</form>
	</div>

{% endblock %}